package com.company.zoj;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by v on 17-5-2.
 */
public class ZojTest1789 {
    private static Node[] students=new Node[30000];
    private static int n;
    private static int m;

    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        while (true){
            n=input.nextInt();
            m=input.nextInt();
            init();

            if(n==0&&m==0){
                return;
            }

            for(int i=0;i<m;i++){
                List<Integer> list=new ArrayList<>();
                int t=input.nextInt();
                for(int j=0;j<t;j++){
                    list.add(input.nextInt());
                }

                mergeList(list);
            }
            System.out.println(statistical());
        }

    }

    private static void init(){
        for(int i=0;i<students.length;i++){
            students[i]=new Node(i);
        }
    }

    private static class Node{
        int left;
        int right;
        int index;

        public Node(int index){
            left=-1;
            right=-1;
            this.index=index;
        }
    }

    private static void merge(Node n1,Node n2){
        while (n1.left!=-1){
            n1=students[n1.left];
        }

        while (n2.right!=-1){
            n2=students[n2.right];
        }

        n2.right=n1.index;
        n1.left=n2.index;
    }

    private static boolean isConnect(Node n1,Node n2){
        while (n1.left!=-1){
            n1=students[n1.left];
        }

        while (n2.left!=-1){
            n2=students[n2.left];
        }

        if(n1.index==n2.index){
            return true;
        }else {
            return false;
        }
    }

    private static int statistical(){
        int suspect=1;

        int n1=students[0].left;
        int n2=students[0].right;
        while (n1!=-1){
            n1=students[n1].left;
            suspect++;
        }

        while (n2!=-1){
            n2=students[n2].right;
            suspect++;
        }

        return suspect;
    }

    private static void mergeList(List<Integer> list){
        for(int i=1;i<list.size();i++){
            if(!isConnect(students[list.get(i-1)],students[list.get(i)])){
                merge(students[list.get(i-1)],students[list.get(i)]);
            }
        }
    }
}
